#!/usr/bin/env node

const router = require('koa-router')();
      log    = console.log;

router.prefix('/api/tasks');

router.get('/', async (ctx,next)=>{//router中可以不写next
    let {page,limit} = ctx.query;//解析查询字符串

    log(ctx.header['user-agent']);//解析请求头
    log(`得到代办事项列表,page = ${page}, limit = ${limit}`);
    ctx.body = '查询成功';
});

router.post('/', async (ctx,next)=>{
    let {task} = ctx.request.body;//解析请求体

    log(`提交代办事项, task : ${task}`);
    ctx.body = '添加成功';
});
  
router.put('/:id', async (ctx,next)=>{
    let {id} = ctx.params;
    let {task} = ctx.request.body;
    log(`修改代办事项, id=${id}, task:${task}`);
    ctx.body = '修改成功';
});

router.delete('/:id',async (ctx,next)=>{
    let {id} = ctx.params;
    log(`删除代办事项, id=${id}`);
    ctx.body = '删除成功';
});

module.exports = router;

